﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ArrayUtilHelpV2
{
    public sealed class ArrayToolV2
    {
        public static T[] Copy<T>(T[] source, int startIndex, int endIndex)
        {
            try
            {
                if (startIndex < endIndex)
                {
                    int _len = endIndex - startIndex;
                    T[] _destination = new T[_len];
                    Array.Copy(source, startIndex, _destination, 0, _len);
                    return _destination;

                }
                return null;
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("ArrayCopy Exception:{0}", ex.Message.Trim()));
            }
        }
        public static void Reverse(Array array, int startIndex, int endIndex)
        {
            try
            {
                Array.Reverse(array, startIndex, endIndex);
            }
            catch (Exception ex)
            {
                throw new Exception(string.Format("Reverse Exception:{0}", ex.Message.Trim()));
            }
        }
        public static bool Equals(byte[] source, byte[] compare)
        {
            if (source == null || compare == null)
                return false;
            if (source.Length != compare.Length)
                return false;
            for (int i = 0; i < source.Length; i++)
                if (source[i] != compare[i])
                    return false;
            return true;
        }
    }
}
